<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

Class Admin_model extends CI_Model{

	private $table = "admin_users";

    function __construct()
    {
        parent::__construct();
    }

	function insert_data($data=array()){
 		if($data != ''){
 			$val=array(
 				'admin_username'=>$data['admin_username'],
				'admin_password'=>md5($data['admin_password']),
				'admin_fname'=>$data['admin_fname'],
				'admin_lname'=>$data['admin_lname'],
				'admin_position'=>$data['admin_position']
 			);

 			$rs = $this->check_insert($this->table,$data['admin_id']);
 			$is = ($rs > 0) ? FALSE : ($this->db->insert($this->table,$val)) ? TRUE : FALSE;
 			return $is;

 		}
 	}

 	function check_insert($table,$val){
 		$rs = $this->db->where('admin_id',$val)->get($table);
 		$count = $rs->num_rows();
 		return $count;
 	}

 	function select_by_table($val){
 		$query = $this->db->get($val)->result();
 		return $query;
 	}

 	function select_by_filter($id)
	{
		$rs=$this->db->where('admin_id',$id)->get($this->table)->row_array();
		return $rs;
	}

	function update_data($data=array()){
 		if($data != ''){
 		$val=array(
 				'admin_username'=>$data['admin_username'],
				'admin_password'=>md5($data['admin_password']),
				'admin_fname'=>$data['admin_fname'],
				'admin_lname'=>$data['admin_lname'],
				'admin_position'=>$data['admin_position']
 			);

 			$is = ($this->db->where('admin_id',$data['admin_id'])->update($this->table,$val)) ? TRUE : FALSE;
 			return $is;
 		}
	}

	function delete_data($data){
		($this->db->where('admin_id',$data)->delete($this->table)) ? $is = TRUE : $is = FALSE;
		return $is;
	}















}
?>